package edu.jinghuan.lms.controller;

import edu.jinghuan.lms.common.result.Result;
import edu.jinghuan.lms.entity.OverdueConfig;
import edu.jinghuan.lms.service.OverdueConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/overdue-config")
public class OverdueConfigController {

    @Autowired
    private OverdueConfigService overdueConfigService;

    @PostMapping
    public Result<OverdueConfig> setOverdueDays(@RequestBody Integer days) {
        try {
            OverdueConfig config = overdueConfigService.setOverdueDays(days);
            return Result.success(config);
        } catch (IllegalArgumentException e) {
            return Result.error(400, e.getMessage());
        }
    }

    @GetMapping
    public Result<OverdueConfig> getCurrentConfig() {
        OverdueConfig config = overdueConfigService.getCurrentConfig();
        return Result.success(config);
    }
}
